home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / MPPScreenModeNames.c < prev    next >
C/C++ Source or Header  |  1998-10-17  |  5KB  |  157 lines

  1. #include "mpp.h"
  2. #include <graphics/displayinfo.h>
  3.  
  4.  
  5.  
  6. STRPTR GetModeName(ULONG DisplayID)
  7. {
  8.   ULONG   alllen,
  9.           deflen,
  10.           len,
  11.           monlen;
  12.   UBYTE   monname[40];
  13.   STRPTR  retval=0;
  14.   struct  NameInfo nameinfo;
  15.   STRPTR  deflabel,
  16.           all;
  17.  
  18.   deflabel=GetString(MSG_OLD_SCREENMODES);
  19.   deflen  =strlen(deflabel);
  20.   deflen  =((DisplayID & MONITOR_ID_MASK) ? 0 : deflen); 
  21.   all     =GetString(MSG_ALL_SCREENMODES);
  22.   alllen  =strlen(all);
  23.   
  24.   if(DisplayID == INVALID_ID)
  25.   {
  26.     return(0);
  27.   }
  28.   else
  29.   {
  30.     if((DisplayID & ALL_MODES) == ALL_MODES)
  31.     {
  32.       if(monlen=GetMonitorName(DisplayID,monname,40))
  33.       {
  34.         len=monlen + deflen + alllen + 1 + 1;
  35.         //                             ^ from "%s:%s"
  36.         
  37.         if(retval=AllocVec(len,MEMF_PUBLIC))
  38.         {
  39.           if(deflen)
  40.             strcpy(retval,deflabel);
  41.           sprintf(&retval[deflen],"%s:%s", monname, all);
  42.         }
  43.       }
  44.     }
  45.     else
  46.     {
  47.       if(GetDisplayInfoData(0,(UBYTE *)&nameinfo,sizeof(nameinfo), DTAG_NAME, DisplayID)>0)
  48.       {
  49.         if(nameinfo.Name)
  50.         {
  51.           if(retval=AllocVec(strlen(nameinfo.Name)+1+deflen,MEMF_PUBLIC))
  52.           {
  53.             if(deflen)
  54.               strcpy(retval,deflabel);
  55.             strcpy(&retval[deflen], nameinfo.Name);
  56.           }
  57.         }
  58.       }
  59.     
  60.       /* Attempt  Monitor: Width x Height */
  61.       if(!retval)
  62.       {
  63.         struct DimensionInfo diminfo;
  64.         struct  DisplayInfo dispinfo;
  65.     
  66.         if(monlen=GetMonitorName(DisplayID,monname,40))
  67.         {
  68.           if((GetDisplayInfoData(0,(UBYTE *)&diminfo ,sizeof(diminfo) , DTAG_DIMS, DisplayID)>0) && 
  69.              (GetDisplayInfoData(0,(UBYTE *)&dispinfo,sizeof(dispinfo), DTAG_DISP, DisplayID)>0) )
  70.           {
  71.             len=monlen + deflen + 39 +1;
  72.             // "#### x #### AA LACED HAM EHB DUALPF PF2" 39
  73.             if(retval=AllocVec(len,MEMF_PUBLIC))
  74.             {
  75.               if(deflen)
  76.                  strcpy(retval,deflabel);
  77.               sprintf(&retval[deflen],"%s:%4d x %4d",
  78.                               monname,
  79.                               (diminfo.Nominal.MaxX+1) & 0xffff,
  80.                               (diminfo.Nominal.MaxY+1) & 0xffff);
  81.               /*
  82.               if(dispinfo.PropertyFlags & DIPF_IS_)
  83.                 strcat(retval,"");
  84.               */
  85.               /*
  86.               if(dispinfo.PropertyFlags & DIPF_IS_AA)
  87.                 strcat(retval," AA");
  88.   */
  89.               if(dispinfo.PropertyFlags & DIPF_IS_DUALPF)
  90.                 strcat(retval," DPF");
  91.               
  92.               if(dispinfo.PropertyFlags & DIPF_IS_PF2PRI)
  93.                 strcat(retval," PF2");
  94.   
  95.               if(dispinfo.PropertyFlags & DIPF_IS_HAM)
  96.                 strcat(retval," HAM");
  97.                 
  98.               if(dispinfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE)
  99.                 strcat(retval," EHB");
  100.                 
  101.               if(dispinfo.PropertyFlags & DIPF_IS_LACE)
  102.                 strcat(retval," Laced");
  103.   
  104.             }
  105.           }
  106.         }
  107.       }
  108.      
  109.       /* Last ditch effort, just display the DisplayID in hex */
  110.       if(!retval)  
  111.         if(retval=AllocVec(12,MEMF_PUBLIC))
  112.           sprintf(retval,"ID:%8x",DisplayID);
  113.     }
  114.   }
  115.   return(retval);
  116. }
  117.  
  118.  
  119. ULONG GetMonitorName(ULONG DisplayID, STRPTR Buffer, ULONG BufferLen)
  120. {
  121.   struct MonitorSpec *monspec;
  122.   ULONG rv=0;
  123.  
  124.   
  125.   Buffer[0]=0;//                                                                                       (4.57.7)
  126.   
  127.   if(DisplayID == INVALID_ID)//                                                 (4.57.7)
  128.   { // if DisplayID = INVALID_ID//                                                                     (4.57.7)
  129.     strncpy(Buffer,GetString(MSG_ANY_MONITOR),BufferLen);//                                            (4.57.7)
  130.     BufferLen--;//                                                                                     (4.57.7)
  131.     Buffer[BufferLen]=0;//                                                                             (4.57.7)
  132.     rv=strlen(Buffer);//                                                                               (4.57.7)
  133.   }//                                                                                                  (4.57.7)
  134.   else
  135.   {
  136.     if(monspec=OpenMonitor(0,DisplayID & MONITOR_ID_MASK))
  137.     {
  138.       strncpy(Buffer,monspec->ms_Node.xln_Name,BufferLen);
  139.       BufferLen--;
  140.       Buffer[BufferLen]=0;
  141.         
  142.       // copy mon name an capitalize     
  143.       for(rv=0;rv<BufferLen && Buffer[rv]!=0;rv++)
  144.       {
  145.         Buffer[rv]=ToUpper(Buffer[rv]);
  146.         if(Buffer[rv]=='.')
  147.            Buffer[rv]=0;
  148.       }
  149.       Buffer[BufferLen]=0;
  150.     
  151.       CloseMonitor(monspec);
  152.     }
  153.   }
  154.   return(rv);
  155. }
  156.  
  157.